home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’96 / Sessions ’96 / Advanced Memory Mgmt / alloc_gla.c1.0.10 / DebugMacros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-17  |  913 b   |  27 lines  |  [TEXT/SPM ]

  1. /*******************************************************************************
  2. **    DebugMacros.h
  3. **
  4. **    Copyright ©1996, Symantec Corp. and Glenn L. Austin
  5. **    All rights reserved worldwide
  6. *******************************************************************************/
  7.  
  8. #pragma once
  9.  
  10. static char* __debugFileName = __FILE__;
  11.  
  12. static void* __newmalloc(size_t sz, char* fileName, long lineNumber)
  13. {
  14.     char*    p = (char*) malloc(sz + sizeof(char*) + sizeof(long));
  15.     
  16.     *(char**) p = fileName;
  17.     *(sizeof(char*) + p) = lineNumber;
  18.     
  19.     return (void*) (sizeof(char*) + sizeof(long) + p);
  20. }
  21.  
  22. #define __GetRealPtr(p)    ((void*) ((char*) p - sizeof(char*) - sizeof(long))
  23.  
  24. #define MALLOC(sz)    __newmalloc(sz, __debugFileName, __LINE__)
  25. #define CALLOC(sz1,num)    __newmalloc(sz1 * num, __debugFileName, __LINE__)
  26. #define REALLOC(p, sz)    realloc(__GetRealPtr(p), sz + sizeof(char*) + sizeof(long))
  27. #define FREE(p)    free(__GetRealPtr(p))